package com.tjhk.java.tech.thread.delay;

import java.util.Random;
import java.util.concurrent.DelayQueue;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class DelayedQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        DelayQueue<DelayedTask> tasks = Stream.concat(new Random(47).ints(5,0,10000)
                .mapToObj(DelayedTask::new),
                Stream.of(new DelayedTask.EndTask(2000)))
                .collect(Collectors.toCollection(DelayQueue::new));
        while (tasks.size() > 0){
            tasks.take().run();
        }
    }
}
